// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Page({
  data: {
    motto: 'Hello World',
    userInfo: {
      avatarUrl: defaultAvatarUrl,
      nickName: '',
    },
    hasUserInfo: false,
    canIUseGetUserProfile: wx.canIUse('getUserProfile'),
    canIUseNicknameComp: wx.canIUse('input.type.nickname'),
    isShow: false,
    yxInfo: null,
    sysInfo:{}
  },
  onLoad() {
    console.log('设备类型', wx.getDeviceInfo())
    // wx.showLoading({
    //   title: '加载中',
    // })
  },
  bindViewTap() {
    
  },
  loginFunc()  {
    console.log('登录')
    wx.getLocation({
      type: 'gcj02',
      success (res) {
        console.log('位置', res)
        // const latitude = res.latitude
        // const longitude = res.longitude
        // const speed = res.speed
        // const accuracy = res.accuracy
      }
    })     
  },
  getPhoneNumber(e) {
    console.log('获取手机号', e)
    this.setData({
      isShow: true
    })
  },
  // 打开客服
  openContact(e) {
    console.log('客服', e)
    wx.navigateTo({
      url: '#小程序://朴朴超市/JZX4YlNOJeIUQBE'
      // target: 'miniProgram',
      // 'open-type': 'navigate',
      // 'short-link': '#小程序://朴朴超市/JZX4YlNOJeIUQBE',
    })
  },
  closePopup() {
    this.setData({
      isShow: false
    })
  },
  openConcant(){
    console.log('wewe',this.getIpxJudgment())
    
    
  },
  getIpxJudgment: function() {
    
    return this.sysInfo || (this.sysInfo = this.getSystemInfoSync()), !!this.sysInfo.model && /(iPhone\sX)|(iPhone12,[^8])|(iPhone13)/.test(this.sysInfo.model)
  },
  getSystemInfoSync: function() {
    var n = this.sysInfo;
    if (!n) try {
      n = wx.getSystemInfoSync(), this.sysInfo = n
    } catch (t) {
      n = {}
    }
    
    let a = /(iPhone\sX)|(iPhone12,[^8])|(iPhone13)/.test(this.sysInfo.model)
    console.log('ASDHKHD:',n,a)
    return n
  },

  addCard(){
    wx.addCard({
      cardList: [
        {
          cardId: 'pZsmt0UaO1SD0gXEOkXdsEVVXbjA',
          cardExt: JSON.stringify({timestamp:1755858698,nonce_str:'sZyWZr',signature:'6b017a04b7ad8e4f994073e7462a1c9222b3cf0d'})
        }
      ],
      success (res) {
        console.log(res.cardList) // 卡券添加结果
      },
      fail(err){
        console.log('cccccc',err)
      }
    })
  },
  open(){
    console.log('aaaaaaa')
    wx.openCustomerServiceChat({
      corpId: 'wwd69673c38f442122',
      extInfo: {
        url: 'https://support.weixin.qq.com/cgi-bin/mmsupport-bin/readtemplate?t=page/common_page__upgrade&btn_text=btn_text_0&text=text000',
      },
      success(res) {
        console.log('ccccc')
      },
      fail(res){
        console.log('bbbbbb',res)
      },
      complete(){
        console.log('aaaaa')
      }
    })
  },
  getYxFunc() {
    let that = this;
    let w = wx.createSelectorQuery().select('.box1');
    let w1 = wx.createSelectorQuery().selectAll('.box1');
    console.log('wwww', w.boundingClientRect());
    console.log('wwww1', w1.boundingClientRect());

    w.boundingClientRect(function(rect){
      // rect.id      // 节点的ID
      // rect.dataset // 节点的dataset
      // rect.left    // 节点的左边界坐标
      // rect.right   // 节点的右边界坐标
      // rect.top     // 节点的上边界坐标
      // rect.bottom  // 节点的下边界坐标
      // rect.width   // 节点的宽度
      // rect.height  // 节点的高度
      console.log('1111', rect)
      that.setData({
        yxInfo: JSON.stringify(rect)
      })
    }).exec()
  }
})
